import React, { Component } from 'react'

export default class App extends Component {

  constructor(props) {
    super(props)
    this.state = {
      username: ""
    }
  }

  render() {
    return (
      <div>
        <form onSubmit={e => { this.handleSubmit(e) }}>
          <label htmlFor="username">
            {/* 受控组件 */}
            <input type="text" 
                   id="username" 
                   onChange={ e => this.handleChange(e) } 
                   valye={this.state.username}/>
          </label>
          <input type="submit" value="提交"/>
        </form>
      </div>
    )
  }
  handleSubmit(event) {
    event.preventDefault()

    console.log(this.state.username)

  }

  handleChange(event) {
    this.setState({
      username: event.target.value
    })
  }
}
